/*
* Copyright (c) 2010 Michael Collins
*
* This file is part of TerraFirma.
*
* TerraFirma is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TerraFirma is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with TerraFirma.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TIMER_H
#define TIMER_H

//#include <ctime>
#include "config.h"
#include <stdint.h>

/**
 * A timer class used for measuring time periods, utilizes the cpu clock for high-precision
 *
 * BUG: A problem may arise if the user has a CPU with auto frequency-scaling, but does not
 * support the scaling of the clock timer. clock() may not be accurate on these processors
 */
namespace engine
{
    /** Time expressed in number of milliseconds
    Be aware that if your CPU hardware does not have a timer
    resolution of at least a millisecond, this will crash. We need
    that high-performance shit!
    */
    typedef uint64_t time;

    class timer
    {
    public:
        timer();

        time get_elapsed_time() const;
        time elapsed() const;
        unsigned int get_elapsed_seconds() const;
        time get_elapsed_milliseconds() const;

        void reset();
    private:
        static time system_msec();
        time start_time;
        #ifdef TF_WINDOWS
        static uint64_t freq;
        static double KHz;
        #else
        //Posix
        #endif
    };

}
#endif // TIMER_H
